Apache Virtual Host Configuration: Setting Up Multiple Websites on Linux

### Guide to Virtual Hosting and Apache Multi-Site Configuration This article introduces configuring virtual hosts on Linux servers using Apache to run multiple websites on a single server, which saves resources and is suitable for individuals/small teams. Virtual hosts are divided into domain-based and IP-based, with a core focus on domain-based configuration. Steps: 1. **Install Apache** (Ubuntu: `sudo apt install apache2`; CentOS: `sudo yum install httpd`), then start and enable auto-start on boot; 2. **Create website directories and files** (e.g., `/var/www/site1/public`), and write a test homepage; 3. **Configure virtual hosts**: Create an independent configuration file (e.g., `site1.conf`) in Apache's configuration directory (e.g., Ubuntu's `/etc/apache2/sites-available`), setting parameters like `ServerName` and `DocumentRoot`; 4. **Enable the configuration** (e.g., `a2ensite` for Ubuntu), then restart Apache to apply changes. Testing: Locally simulate domain access by modifying the `hosts` file; publicly, resolve the domain to the server IP via DNS. Common issues like insufficient permissions or configuration errors can be resolved through permission settings or syntax checks. Summary: After completing installation, directory creation, virtual host configuration, and testing, multiple sites can run in isolation.

Read More